package kr.hkit.powerjava.chapter08;

/** 은행계좌
 * owner - 예금주
 * accountNumber - 계좌번호
 * balance - 예금 잔액
 * @author 200-3
 */
public class BankAccount {
	private String owner;
	private int accountNumber;
	private int balance;
		
	public BankAccount(String owner, int accountNumber, int balance) {
		this.owner = owner;
		this.accountNumber = accountNumber;
		this.balance = balance;
	}

	/** 예금
	 * @param amount 입금액
	 */
	public void deposit(int amount){
		balance += amount;
	}
	
	public int withdraw(int amount){
		if (balance < amount || balance == 0){
			System.out.println("출금 불가, 현재 잔액은 " + balance);
			return -111111;
		}else{
			balance -= amount;
			return amount;
		}
	}

	public int transfer(int amount, BankAccount otherAccount){
		if (balance < amount || balance == 0){
			System.out.println("송금 불가, 현재 잔액은 " + balance);
			return -111111;
		}else{
			balance -= amount;
			System.out.println(amount + "원 송금 후 잔액: " + balance);
			otherAccount.balance += amount;
			return amount;
		}
		
	}

	@Override
	public String toString() {
		return "BankAccount [owner=" + owner + ", accountNumber="
				+ accountNumber + ", balance=" + balance + "]";
	}
}
